package com.colorlight.cloud.xm.entity.enumerate;

/**
 * @author Demon
 * @date 6/5/2024  上午9:37
 */

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import com.colorlight.iot.proto.xm.entity.XmEntity;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Demon
 * proto方法类型
 */
@Getter
public enum ParamIndexEnum implements EnumTrans<XmEntity.ParamIndexEnum, ParamIndexEnum> {
	/**
	 * 设置所有
	 * 心跳间隔 单位：millisecond
	 */
	
	ALL(XmEntity.ParamIndexEnum.ALL),
	HB_INTERVAL(XmEntity.ParamIndexEnum.HB_INTERVAL);
	
	private final Integer id;
	private final String name;
	private final XmEntity.ParamIndexEnum paramIndexEnum;
	private static final long serialVersionUID = 987654321987654321L;
	
	ParamIndexEnum(XmEntity.ParamIndexEnum paramIndexEnum) {
		this.id = paramIndexEnum.getNumber();
		this.name = paramIndexEnum.name();
		this.paramIndexEnum = paramIndexEnum;
	}
	
	/**
	 * @param paramIndexEnum
	 * @return 对应的类型
	 */
	public static ParamIndexEnum getScheduleTypeStruct(XmEntity.ParamIndexEnum paramIndexEnum) {
		Objects.requireNonNull(paramIndexEnum, "ParamIndexEnum can not be null.");
		return Arrays.stream(ParamIndexEnum.values())
				.filter(e -> e.name.equals(paramIndexEnum.name()))
				.findFirst()
				.orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
	}
	
	@Override
	public XmEntity.ParamIndexEnum toProto() {
		return this.paramIndexEnum;
	}
	
	@Override
	public ParamIndexEnum formProto(XmEntity.ParamIndexEnum paramIndexEnum) {
		return getScheduleTypeStruct(paramIndexEnum);
	}
}
